package util;

import java.util.Iterator;

import collection.ANode;
import collection.ICircularLinkedList;
import collection.ILinkedList;

public class PrintService {

	public static void print(Object obj)
	{
		System.out.print(obj);
	}
	
	public static void println(Object obj)
	{
		System.out.println(obj);
	}
	
	public static void println()
	{
		System.out.println();
	}
	
	public static <T> void printArray(T[] a)
	{
		if (a.length==0)
		{
			println("{}");
			return ;
		}
		
		print("{");
		for (int i=0; i < a.length - 1; i++)
		{
			print(a[i] + ", ");
		}
		println(a[a.length-1] + "}");
	}
	
	public static void printArray(int[] a)
	{
		if (a.length==0)
		{
			println("{}");
			return ;
		}
		
		print("{");
		for (int i=0; i < a.length - 1; i++)
		{
			print(a[i] + ", ");
		}
		println(a[a.length-1] + "}");
	}
	
	public static void printArray(double[] a)
	{
		if (a.length==0)
		{
			println("{}");
			return ;
		}

		print("{");
		for (int i=0; i < a.length - 1; i++)
		{
			print(a[i] + ", ");
		}
		println(a[a.length-1] + "}");
	}
	
	public static <N extends ANode<T>, T> void printLinkedList(ILinkedList<N, T> list)
	{
		print("[ ");
		for (N node : list)
		{
			print(node + " ");
		}
		println("]");
	}
	
	// Since it is circular, only prints out the first 100 elements to avoid infinite loop
	public static <N extends ANode<T>, T> void printCircularLinkedList(ICircularLinkedList<N, T> list)
	{
		print("[ ");
		int i=0;
		for (N node : list)
		{
			i += 1;
			print(node + " ");
			if (i == 100)
				break;
		}
		println("]");
	}
	
	public static void printHeader(String header)
	{
		println();
		println("----------" + header + "----------");
		println();
	}
	
	public static void printFooter(String footer)
	{
		println();
		println("----------" + footer + "----------");
		println();
	}
	
}
